package tool

import (
	"net/http"
	"fmt"
	"github.com/pkg/errors"
	"com/ys/model"
)

/**
异常处理
 */
func ThrowError(err error) {
	if err != nil {
		panic(errors.WithStack(err))
	}

}

/**
异常捕获
 */
func CatchError(w http.ResponseWriter, r *http.Request) {

	if r := recover(); r != nil { //请求判定
		resp := model.Resp{Code: "9001", Msg: r.(error).Error()}
		ConvertObject2JsonResp(w, resp)
		fmt.Printf("%+v\n", r.(error))

	}

}
